package com.ytjj.qmyx.supplychain.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.ytjj.qmyx.supplychain.common.api.CommonPage;
import com.ytjj.qmyx.supplychain.common.exception.ApiException;
import com.ytjj.qmyx.supplychain.common.model.request.ProductLibraryRequest;
import com.ytjj.qmyx.supplychain.common.model.request.ProductLibrarySpecRequest;
import com.ytjj.qmyx.supplychain.common.model.request.ProductSelectRequest;
import com.ytjj.qmyx.supplychain.common.model.response.CategoryResponse;
import com.ytjj.qmyx.supplychain.common.model.response.ProductCategoryResponse;
import com.ytjj.qmyx.supplychain.common.model.response.ProductLibraryResponse;
import com.ytjj.qmyx.supplychain.common.utils.OrderUtils;
import com.ytjj.qmyx.supplychain.mapper.*;
import com.ytjj.qmyx.supplychain.mapper.entity.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

@Slf4j
@Service
public class ProductLibraryService {
    @Resource
    private ProductLibraryMapper productLibraryMapper;
    @Resource
    private ProductCategoryMapper productCategoryMapper;
    @Resource
    private BankerMapper bankerMapper;
    @Resource
    private BankerService bankerService;
    @Resource
    private ProductLibrarySpecMapper productLibrarySpecMapper;
    @Resource
    private ProductSelectMapper productSelectMapper;
    @Resource
    private ProductLibrarySkuKeyMapper productLibrarySkuKeyMapper;
    @Resource
    private ProductSelectSkuKeyMapper productSelectSkuKeyMapper;
    @Resource
    private ProductLibrarySkuValueMapper productLibrarySkuValueMapper;
    @Resource
    private ProductSelectSkuValueMapper productSelectSkuValueMapper;
    @Resource
    private ProductSelectSpecMapper productSelectSpecMapper;
    @Resource
    private ProductAttributeKeyMapper productAttributeKeyMapper;
    @Resource
    private ProductAttributeValueMapper productAttributeValueMapper;

    public CommonPage<YxProductLibrary> selectList(ProductLibraryRequest productLibraryRequest) {
        YxBanker userInfo = bankerService.getUserInfo();
        productLibraryRequest.setLevel(userInfo.getLevel());
        if (productLibraryRequest.getLevel() != 0) {
            productLibraryRequest.setBankerId(userInfo.getId());
        } else {
            productLibraryRequest.setBankerId(null);
            productLibraryRequest.setBankerName(productLibraryRequest.getBankerName());
        }
        Example example = new Example(YxProductLibrary.class);
        Example.Criteria criteria = example.createCriteria();
        if (null != productLibraryRequest.getBankerId()) {
            criteria.andEqualTo("bankerId", productLibraryRequest.getBankerId());
        }
        if (!StringUtils.isEmpty(productLibraryRequest.getProductName())) {
            criteria.andLike("productName", "%" + productLibraryRequest.getProductName() + "%");
        }
        if (null != productLibraryRequest.getIsSelect()) {
            criteria.andEqualTo("isSelect", productLibraryRequest.getIsSelect());
        }
        if (!StringUtils.isEmpty(productLibraryRequest.getBankerName())) {
            criteria.andEqualTo("bankerName", productLibraryRequest.getBankerName());
        }
        if (null != productLibraryRequest.getStatus()) {
            criteria.andEqualTo("status", productLibraryRequest.getStatus());
        }

        PageHelper.startPage(productLibraryRequest.getPageNum(), productLibraryRequest.getPageSize());
        List<YxProductLibrary> page = productLibraryMapper.selectByExample(example);
        if (!CollectionUtils.isEmpty(page)) {
            for (YxProductLibrary productLibraryResponse : page) {
                //根据categoryId拿到的是二级分类信息
                YxProductCategory yxProductCategory = productCategoryMapper.selectByPrimaryKey(productLibraryResponse.getCategroyPid());
                if (yxProductCategory != null) {
                    productLibraryResponse.setCategoryTitle(yxProductCategory.getTitle());
                }
                //获取一级分类信息
                if (yxProductCategory != null && yxProductCategory.getPid() != 0) {
                    YxProductCategory pcTop = productCategoryMapper.selectByPrimaryKey(productLibraryResponse.getCategoryId());
                    productLibraryResponse.setCategoryTopTitle(pcTop.getTitle());
                } else if (yxProductCategory != null && yxProductCategory.getPid() == 0) {
                    productLibraryResponse.setCategoryTopTitle(yxProductCategory.getTitle());
                }
                //获取bankerName
                YxBanker banker = bankerMapper.selectByPrimaryKey(productLibraryResponse.getBankerId());
                if (banker != null) {
                    productLibraryResponse.setBankerName(banker.getName());
                }
            }
        }
        return CommonPage.restPage(page);
    }

    public String getZipUrl(Integer id) {
        YxProductLibrary yxProductLibrary = productLibraryMapper.selectByPrimaryKey(id);
        return yxProductLibrary.getZipUrl();
    }

    public void updateProductLibraryStock(Integer id, Integer stock) {
        YxProductLibrarySpec yxProductLibrarySpec = new YxProductLibrarySpec();
        yxProductLibrarySpec.setStock(stock);
        yxProductLibrarySpec.setId(id);
        productLibrarySpecMapper.updateByPrimaryKeySelective(yxProductLibrarySpec);
    }

    public CommonPage<YxProductLibrarySpec> getProductSpec(ProductLibrarySpecRequest productLibrarySpecRequest) {
        Example example = new Example(YxProductLibrarySpec.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("status", 1);
        if (null != productLibrarySpecRequest.getSkuSpec()) {
            criteria.andLike("skuSpec", "%" + productLibrarySpecRequest.getSkuSpec() + "%");
        }

        PageHelper.startPage(productLibrarySpecRequest.getPageNum(), productLibrarySpecRequest.getPageSize());
        List<YxProductLibrarySpec> list = productLibrarySpecMapper.selectByExample(example);
        return CommonPage.restPage(list);
    }

    public void addProductLibrary(ProductLibraryRequest productLibraryRequest) {
        YxBanker bankerInfo = bankerService.getUserInfo();
        YxProductLibrary yxProductLibrary = new YxProductLibrary();
        yxProductLibrary.setBankerId(bankerInfo.getId());
        yxProductLibrary.setCategoryId(productLibraryRequest.getCategoryId());
        yxProductLibrary.setCategroyPid(productLibraryRequest.getCategroyPid());
        yxProductLibrary.setWarehouse(productLibraryRequest.getWarehouse());
        yxProductLibrary.setProductNo(OrderUtils.getProductNo());
        yxProductLibrary.setProductName(productLibraryRequest.getProductName());
        yxProductLibrary.setProductImg(productLibraryRequest.getProductImg());
        yxProductLibrary.setDescr(productLibraryRequest.getDescr());
        yxProductLibrary.setStatus(productLibraryRequest.getStatus());
        yxProductLibrary.setCostPrice(productLibraryRequest.getCostPrice());
        yxProductLibrary.setStock(productLibraryRequest.getStock());
        yxProductLibrary.setRate(productLibraryRequest.getRate());
        yxProductLibrary.setIsCertificate(productLibraryRequest.getIsCertificate());
        yxProductLibrary.setManufacturer(productLibraryRequest.getManufacturer());
        yxProductLibrary.setManufacturerAddress(productLibraryRequest.getManufacturerAddress());
        yxProductLibrary.setManufacturerTel(productLibraryRequest.getManufacturerTel());
        yxProductLibrary.setWarrantyPeriod(productLibraryRequest.getWarrantyPeriod());
        yxProductLibrary.setNormalExpress(productLibraryRequest.getNormalExpress());
        yxProductLibrary.setAfterSalesProblem(productLibraryRequest.getAfterSalesProblem());
        yxProductLibrary.setReturnAddress(productLibraryRequest.getReturnAddress());
        yxProductLibrary.setReturnTel(productLibraryRequest.getReturnTel());
        yxProductLibrary.setInstallVideo(productLibraryRequest.getInstallVideo());
        yxProductLibrary.setCreateTime(new Date());
        yxProductLibrary.setZipUrl(productLibraryRequest.getZipUrl());
        yxProductLibrary.setBankerName(bankerInfo.getName());
        productLibraryMapper.insertSelective(yxProductLibrary);

        // 处理数据
        // 属性value id 集合
        List<Integer> attributeValueIds = productLibraryRequest.getAttributeValueIds();
        if (attributeValueIds.size() <= 0) {
            throw new ApiException("sku属性不能为空！");
        }
        // 根据选择的属性value id集合转化数据
        List<Map<String, Object>> list = this.getCheckedSpan(attributeValueIds);
        if (list.size() > 2) {
            throw new ApiException("sku属性不能选择两个以上的key！");
        }
        String specJson = JSON.toJSONString(list);
        // 规格
        yxProductLibrary.setAttributeJson(specJson);
        productLibraryMapper.updateByPrimaryKeySelective(yxProductLibrary);

        // 新增商品规格表
        List<String> skuSpec = this.getDetailByJson(specJson);
        if (!CollectionUtils.isEmpty(skuSpec)) {
            for (String skuSpecStr : skuSpec) {
                YxProductLibrarySpec yxProductLibrarySpec = new YxProductLibrarySpec();
                yxProductLibrarySpec.setProductId(yxProductLibrary.getId());
                yxProductLibrarySpec.setSkuSpec(skuSpecStr);
                yxProductLibrarySpec.setPrice(yxProductLibrary.getCostPrice());
                yxProductLibrarySpec.setProImg(yxProductLibrary.getProductImg());
                yxProductLibrarySpec.setStock(0);
                yxProductLibrarySpec.setStatus((byte) 1);
                yxProductLibrarySpec.setCreateTime(new Date());
                productLibrarySpecMapper.insertSelective(yxProductLibrarySpec);
            }
        }
        Map<Integer, Object> param = new HashMap<>();
        // 新增商品sku属性key-value表数据
        for (Integer attributeValueId : attributeValueIds) {
            YxProductAttributeValue productAttributeValue = productAttributeValueMapper.selectByPrimaryKey(attributeValueId);
            YxProductAttributeKey productAttributeKey = productAttributeKeyMapper.selectByPrimaryKey(productAttributeValue.getAttributeId());

            // 新增sku属性key
            if (param.get(productAttributeKey.getId()) == null) {
                YxProductLibrarySkuKey yxProductLibrarySkuKey = new YxProductLibrarySkuKey();
                yxProductLibrarySkuKey.setPid(yxProductLibrary.getId());
                yxProductLibrarySkuKey.setKid(productAttributeKey.getId());
                yxProductLibrarySkuKey.setSort(productAttributeKey.getSort());
                yxProductLibrarySkuKey.setName(productAttributeKey.getAttributeName());
                yxProductLibrarySkuKey.setCreateTime(new Date());
                productLibrarySkuKeyMapper.insert(yxProductLibrarySkuKey);
                param.put(productAttributeKey.getId(), yxProductLibrarySkuKey);
            }

            // 新增sku属性value
            YxProductLibrarySkuValue productSkuValue = new YxProductLibrarySkuValue();
            productSkuValue.setPid(yxProductLibrary.getId());
            productSkuValue.setVid(attributeValueId);
            productSkuValue.setValue(productAttributeValue.getAttributeValue());
            productSkuValue.setSort(productAttributeValue.getSort());
            productSkuValue.setStatus((byte) 1);
            productSkuValue.setCreateTime(new Date());
            productLibrarySkuValueMapper.insert(productSkuValue);
        }
    }

    public List<CategoryResponse> getCategoryList() {
        YxProductCategory yxProductCategory = new YxProductCategory();
        yxProductCategory.setPid(0);
        yxProductCategory.setStatus((byte) 1);
        List<YxProductCategory> yxProductCategoryList = productCategoryMapper.select(yxProductCategory);
        return yxProductCategoryList.stream()
                .map(item -> {
                    ProductCategoryResponse response = new ProductCategoryResponse();
                    BeanUtils.copyProperties(item, response);
                    CategoryResponse categoryResponse = new CategoryResponse(response);
                    YxProductCategory yxProductCategory1 = new YxProductCategory();
                    yxProductCategory1.setPid(item.getId());
                    yxProductCategory1.setStatus((byte) 1);
                    List<YxProductCategory> childrenCategoryList = productCategoryMapper.select(yxProductCategory1);
                    List<ProductCategoryResponse> categoryResponseList = new ArrayList<>();
                    if (!CollectionUtils.isEmpty(childrenCategoryList)) {
                        childrenCategoryList.stream().forEach(children -> {
                            ProductCategoryResponse productCategoryResponse = new ProductCategoryResponse();
                            BeanUtils.copyProperties(children, productCategoryResponse);
                            categoryResponseList.add(productCategoryResponse);
                        });
                    }
                    categoryResponse.setChildCategoryList(categoryResponseList);
                    return categoryResponse;
                }).collect(Collectors.toList());
    }

    public List<YxProductCategory> getTopCategoryList() {
        YxProductCategory yxProductCategory = new YxProductCategory();
        yxProductCategory.setPid(0);
        yxProductCategory.setStatus((byte) 1);
        List<YxProductCategory> yxProductCategoryList = productCategoryMapper.select(yxProductCategory);
        return yxProductCategoryList;
    }

    public List<YxProductCategory> getChildCategoryList(Integer id) {
        YxProductCategory yxProductCategory = new YxProductCategory();
        yxProductCategory.setPid(id);
        yxProductCategory.setStatus((byte) 1);
        List<YxProductCategory> yxProductCategoryList = productCategoryMapper.select(yxProductCategory);
        return yxProductCategoryList;
    }

    public List<Map<String, Object>> getSpecListByCategoryId(Integer categoryId) {
        // 根据商品属性id集合获取规格List
        List<Map<String, Object>> specArray = this.getSpecListByAttributeKeyIds(categoryId);
        return specArray;
    }

    public int insertAttributeValue(Integer attributeId, String value) {
        if (isSpecialChar(value.trim())) {
            throw new ApiException("属性不能包含特殊字符");
        } else {
            YxProductAttributeValue yxProductAttributeValue = new YxProductAttributeValue();
            yxProductAttributeValue.setAttributeId(attributeId);
            yxProductAttributeValue.setAttributeValue(value);
            yxProductAttributeValue.setCreateTime(new Date());
            return productAttributeValueMapper.insertSelective(yxProductAttributeValue);
        }
    }

    public Integer deleteAttributeValue(Integer id) {
        return productAttributeValueMapper.deleteByPrimaryKey(id);
    }

    /**
     * 判断是否含有特殊字符
     *
     * @param str
     * @return true为包含，false为不包含
     */
    public static boolean isSpecialChar(String str) {
        // String regEx = "[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]|\n|\r|\t]";
        String regEx = "[ _`~!@#$%^&=|{}':;',\\\\[\\\\]<>?~！@#￥%……&（）|{}【】‘；：”“’。，、？]|\\n|\\r|\\t]";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(str);
        return m.find();
    }

    /**
     * 根据商品分类id获取规格List
     *
     * @param productCategoryId
     * @return
     */
    private List<Map<String, Object>> getSpecListByAttributeKeyIds(Integer productCategoryId) {
        List<Map<String, Object>> specArray = new ArrayList<>();
        Example example = new Example(YxProductAttributeKey.class);
        example.createCriteria().andEqualTo("categoryId", productCategoryId);
        List<YxProductAttributeKey> productAttributeKeyList = productAttributeKeyMapper.selectByExample(example);

        List<Integer> attributeKeyIds = productAttributeKeyList.stream()
                .map(YxProductAttributeKey::getId).collect(Collectors.toList());
        if (!CollectionUtils.isEmpty(attributeKeyIds)) {
            for (Integer attributeKeyId : attributeKeyIds) {
                Map<String, Object> specMap = new LinkedHashMap<>();
                Map<String, Object> spanKeysMap = new LinkedHashMap<>();
                YxProductAttributeKey productAttributeKey = productAttributeKeyMapper.selectByPrimaryKey(attributeKeyId);

                Example example1 = new Example(YxProductAttributeValue.class);
                example1.createCriteria().andEqualTo("attributeId", productAttributeKey.getId());
                List<YxProductAttributeValue> productAttributeValueList = productAttributeValueMapper.selectByExample(example1);
                spanKeysMap.put("id", productAttributeKey.getId());
                spanKeysMap.put("name", productAttributeKey.getAttributeName());
                specMap.put("spanName", spanKeysMap);
                if (!CollectionUtils.isEmpty(productAttributeValueList)) {
                    List<Map<String, Object>> spanValues = new ArrayList<>();
                    for (YxProductAttributeValue productAttributeValue : productAttributeValueList) {
                        Map<String, Object> spanValuesMap = new HashMap<>();
                        spanValuesMap.put("id", productAttributeValue.getId());
                        spanValuesMap.put("name", productAttributeValue.getAttributeValue());
                        spanValues.add(spanValuesMap);
                    }
                    specMap.put("spanValue", spanValues);
                }
                specArray.add(specMap);
            }
        }
        return specArray;
    }

    private List<Map<String, Object>> getCheckedSpan(List<Integer> attributeValueIds) {
        Map<String, List<String>> checkedList = new HashMap<>();
        if (!CollectionUtils.isEmpty(attributeValueIds)) {
            for (int i = 0; i < attributeValueIds.size(); i++) {
                Integer attributeValueId = attributeValueIds.get(i);
                YxProductAttributeValue dataValue = productAttributeValueMapper.selectByPrimaryKey(attributeValueId);
                YxProductAttributeKey dataKey = productAttributeKeyMapper.selectByPrimaryKey(dataValue.getAttributeId());
                String key = dataKey.getAttributeName();
                List<String> listValue = checkedList.get(key);
                if (null == listValue || listValue.size() <= 0) {
                    List<String> list = new ArrayList<>();
                    list.add(dataValue.getAttributeValue());
                    checkedList.put(key, list);
                } else {
                    listValue.add(dataValue.getAttributeValue());
                    checkedList.put(key, listValue);
                }
            }
        }
        List<Map<String, Object>> list = new ArrayList<>();
        checkedList.forEach((key, value) -> {
            Map<String, Object> span = new LinkedHashMap<>();
            span.put("spanName", key);
            span.put("spanValue", value);
            list.add(span);
        });
        return list;
    }

    private List<String> getDetailByJson(String specJson) {
        JSONArray jsonArray = JSONArray.parseArray(specJson);
        List<String> spanlist = new ArrayList<>();
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            JSONArray spanValues = jsonObject.getJSONArray("spanValue");
            for (int j = 0; j < spanValues.size(); j++) {
                String span = jsonObject.getString("spanName") + ":" + spanValues.getString(j);
                if (jsonArray.size() == 1) {
                    spanlist.add(span);
                    continue;
                }
                getSpan(i + 1, span, jsonArray, spanlist);
            }
            break;
        }
        return spanlist;
    }

    private void getSpan(int i, String span, JSONArray jsonArray, List spanlist) {
        JSONObject jsonObject = jsonArray.getJSONObject(i);
        JSONArray spanValues = jsonObject.getJSONArray("spanValue");
        for (int j = 0; j < spanValues.size(); j++) {
            span = span + "," + jsonObject.getString("spanName") + ":" + spanValues.getString(j);
            if (i == jsonArray.size() - 1) {
                spanlist.add(span);
                // span = span.split("," + jsonObject.getString("spanName") +":"+ spanValues.getString(j))[0];
            } else {
                getSpan(i + 1, span, jsonArray, spanlist);
            }
            span = span.substring(0, span.indexOf("," + jsonObject.getString("spanName") + ":" + spanValues.getString(j)));
        }
    }

    @Transactional(rollbackFor = Exception.class)
    public int insertProductSelect(ProductSelectRequest productSelectRequest) {
        YxBanker banker = bankerService.getUserInfo();
        if (banker == null) {
            throw new ApiException("该店家id{" + productSelectRequest.getBankerId() + "}不存在！");
        }
        YxProductLibrary ProductLibrary = new YxProductLibrary();
        ProductLibrary.setId(productSelectRequest.getProductLibraryId());
        ProductLibrary.setIsSelect(productSelectRequest.getIsSelect());
        int count = productLibraryMapper.updateByPrimaryKeySelective(ProductLibrary);
        if (count > 0) {

            YxProductLibrary yxProductLibrary = productLibraryMapper.selectByPrimaryKey(productSelectRequest.getProductLibraryId());
            YxProductSelect yxProductSelect = new YxProductSelect();
            yxProductSelect.setProductLibraryId(yxProductLibrary.getId());
            yxProductSelect.setProductNo(yxProductLibrary.getProductNo());
            yxProductSelect.setProductName(yxProductLibrary.getProductName());
            yxProductSelect.setProductImg(yxProductLibrary.getProductImg());
            yxProductSelect.setDescr(yxProductLibrary.getDescr());
            yxProductSelect.setSort(yxProductLibrary.getSort());
            yxProductSelect.setCostPrice(yxProductLibrary.getCostPrice());
            yxProductSelect.setStock(yxProductLibrary.getStock());
            yxProductSelect.setWarehouse(yxProductLibrary.getWarehouse());
            yxProductSelect.setWarehouseName(yxProductLibrary.getBankerName());
            yxProductSelect.setCategoryId(yxProductLibrary.getCategroyPid());
            yxProductSelect.setAttributeJson(yxProductLibrary.getAttributeJson());
            yxProductSelect.setCreateTime(yxProductLibrary.getCreateTime());
            yxProductSelect.setUpdateTime(yxProductLibrary.getUpdateTime());
            yxProductSelect.setBankerId(yxProductLibrary.getBankerId());
            yxProductSelect.setRate(yxProductLibrary.getRate());
            yxProductSelect.setReceStatus((byte) 1);
            yxProductSelect.setCompleteStatus((byte) 0);
            yxProductSelect.setSelectStatus(0);
            count = productSelectMapper.insertSelective(yxProductSelect);
            //添加SkuKey
            YxProductLibrarySkuKey yxProductLibrarySkuKey = new YxProductLibrarySkuKey();
            yxProductLibrarySkuKey.setPid(productSelectRequest.getProductLibraryId());
            List<YxProductLibrarySkuKey> librarySkuKeys = productLibrarySkuKeyMapper.select(yxProductLibrarySkuKey);
            for (YxProductLibrarySkuKey librarySkuKey : librarySkuKeys) {
                YxProductSelectSkuKey productSelectSkuKey = new YxProductSelectSkuKey();
                productSelectSkuKey.setPid(yxProductLibrary.getId());
                productSelectSkuKey.setName(librarySkuKey.getName());
                productSelectSkuKey.setSort(librarySkuKey.getSort());
                productSelectSkuKey.setCreateTime(librarySkuKey.getCreateTime());
                productSelectSkuKey.setUpdateTime(librarySkuKey.getUpdateTime());
                productSelectSkuKey.setAttributeKeyId(librarySkuKey.getKid());

                Example example = new Example(YxProductSelectSkuKey.class);
                example.createCriteria().andEqualTo("pid", librarySkuKey.getPid()).andEqualTo("attributeKeyId", librarySkuKey.getKid());

                YxProductSelectSkuKey productSelectSkuKey1 = productSelectSkuKeyMapper.selectOneByExample(example);
                if (productSelectSkuKey1 == null) {
                    productSelectSkuKeyMapper.insertSelective(productSelectSkuKey);
                }
            }
            // value
            //添加SkuValue
            YxProductLibrarySkuValue yxProductLibrarySkuValue = new YxProductLibrarySkuValue();
            yxProductLibrarySkuValue.setPid(productSelectRequest.getProductLibraryId());
            List<YxProductLibrarySkuValue> librarySkuValues = productLibrarySkuValueMapper.select(yxProductLibrarySkuValue);
            for (YxProductLibrarySkuValue librarySkuValue : librarySkuValues) {
                YxProductSelectSkuValue productSelectSkuValue = new YxProductSelectSkuValue();
                productSelectSkuValue.setPid(librarySkuValue.getPid());
                productSelectSkuValue.setSort(librarySkuValue.getSort());
                productSelectSkuValue.setStatus(librarySkuValue.getStatus());
                productSelectSkuValue.setValue(librarySkuValue.getValue());
                productSelectSkuValue.setCreateTime(librarySkuValue.getCreateTime());
                productSelectSkuValue.setUpdateTime(librarySkuValue.getUpdateTime());
                productSelectSkuValue.setAttributeValueId(librarySkuValue.getVid());

                Example example = new Example(YxProductSelectSkuValue.class);
                example.createCriteria().andEqualTo("pid", librarySkuValue.getPid()).andEqualTo("attributeValueId", librarySkuValue.getVid());

                YxProductSelectSkuValue productSelectSkuValue1 = productSelectSkuValueMapper.selectOneByExample(example);
                if (productSelectSkuValue1 == null) {
                    productSelectSkuValueMapper.insertSelective(productSelectSkuValue);
                }
            }
            //添加规格
            YxProductLibrarySpec yxProductLibrarySpec = new YxProductLibrarySpec();
            yxProductLibrarySpec.setProductId(productSelectRequest.getProductLibraryId());
            List<YxProductLibrarySpec> list = productLibrarySpecMapper.select(yxProductLibrarySpec);
            for (YxProductLibrarySpec productLibrarySpec : list) {
                YxProductSelectSpec productSelectSpec = new YxProductSelectSpec();
                productSelectSpec.setPrice(productLibrarySpec.getPrice());
                productSelectSpec.setProductLibraryId(productLibrarySpec.getProductId());
                productSelectSpec.setProImg(productLibrarySpec.getProImg());
                productSelectSpec.setSkuSpec(productLibrarySpec.getSkuSpec());
                productSelectSpec.setStatus(productLibrarySpec.getStatus());
                productSelectSpec.setStock(productLibrarySpec.getStock());
                productSelectSpec.setCreateTime(productLibrarySpec.getCreateTime());
                productSelectSpec.setUpdateTime(productLibrarySpec.getUpdateTime());
                productSelectSpecMapper.insertSelective(productSelectSpec);
            }
        }


        return count;
    }

    public static void main(String[] args) {
        System.out.println(isSpecialChar("1.5g-片*60片"));
    }

}
